package com.rentapark.app;



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import data.DB;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.content.Intent;
import android.content.SharedPreferences;

//this is the open screen
public class RentAParkActivity extends Activity {
	
    private static final long SPLASH_DISPLAY_LENGHT = 1000;
	/** Called when the activity is first created. */
	final RentAParkActivity thisActivity = this;
	protected boolean _active = true;
	//the open screen is displayed for 2 seconds
	protected int _splashTime = 2000; // time to display the splash screen in ms
	DB db_instance;
	static final int PROGRESS_DIALOG = 0;
	ProgressDialog progressDialog;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

            /* New Handler to start the Menu-Activity 
             * and close this Splash-Screen after some seconds.*/
            new Handler().postDelayed(new Runnable(){
                @Override
                public void run() {
                    /* Create an Intent that will start the Menu-Activity. */
                	SharedPreferences ref = getSharedPreferences("com.ruthy.parkApp",MODE_PRIVATE);
                    if((ref.getString("my_id", "-1").equals("-1")))//if it is a new user- open sign up activity
                    {
                    	Intent intent = new Intent(RentAParkActivity.this, SignUp.class);
            			startActivity(intent);
                    }
                    else	//if it's not a new user- open main screen activity
                    {
                    	
                    	Intent intent = new Intent(thisActivity, MainScreen.class);
            			startActivity(intent);

                    }
                    finish();
                }
            }, SPLASH_DISPLAY_LENGHT);
        }

}